import java.awt.List;
import java.util.ArrayList;
import java.util.Iterator;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;

	public class Webkeywords {
		WebDriver myD = new InternetExplorerDriver();
		//WebDriver myD = new FirefoxDriver();
		//WebDriver myD = new ChromeDriver();
		
		@Test
		public void MyTest()throws Exception{
			
			navigateBrowser(myD, "http://www.kayak.com");
			enterText(myD, "//input[@id='wherebox']", "Midway (MDW) - Chicago, IL");
			selectList(myD, "//select[@id='rooms']", "3 rooms");
			//id=Attribute Name, cbTRAVELOCITYQ320_US_HFDCMP2 = Attribute Value
			checkBox(myD, "//input[@id='cbTRAVELOCITYQ320_US_HFDCMP2']");
			myD.quit();
		}

		
		public void enterText(WebDriver driver, String xPath, String data){
			//		Purpose: Enter Text into a edit field
			//		I/P:driver, xPath, Data
			//		O/P:Nil
			//		CreatedBy:SelA16 Batch
			//		When:9/11/12
			//		EditedBy:Karthik
			//		When:9/11/12
			driver.findElement(By.xpath(xPath)).clear();
			driver.findElement(By.xpath(xPath)).sendKeys(data);
		}
		
		public String readText(WebDriver driver, String xPath){
			//		Purpose: Read Text into a edit field
			//		I/P:driver, xPath
			//		O/P:Data
			//		CreatedBy:SelA16 Batch
			//		When:9/11/12
			//		EditedBy:Karthik
			//		When:9/11/12
			return driver.findElement(By.xpath(xPath)).getText();
		}
		
		public void clickElement(WebDriver driver, String xPath){
			//		Purpose: Click any element on the AUT
			//		I/P:driver, xPath
			//		O/P:Nil
			//		CreatedBy:SelA16 Batch
			//		When:9/11/12
			//		EditedBy:Karthik
			//		When:9/11/12
			driver.findElement(By.xpath(xPath)).click();
			driver.findElement(By.xpath(xPath)).sendKeys("\n");
		}
		
		public void selectList(WebDriver driver, String xPath, String data){
			//		Purpose: Select from a dropdown list
			//		I/P:driver, xPath, data
			//		O/P:Nil
			//		CreatedBy:SelA16 Batch
			//		When:9/11/12
			//		EditedBy:Karthik
			//		When:9/11/12
			Select myDD = new Select(driver.findElement(By.xpath(xPath)));
			//myDD.selectByVisibleText(data);
//			myDD.selectByValue(data);
				
			Iterator<WebElement> it = myDD.getOptions().iterator();
			while(it.hasNext())
			{
				WebElement we =it.next();
				if(we.getText().equals(data))
				{
					we.click();
					break;
				}
			}
		
			
		   	myDD = null;
		}
		
		public void checkBox(WebDriver driver, String xPath){
			//		Purpose: Check a checkbox
			//		I/P:driver, xPath, data
			//		O/P:Nil
			//		CreatedBy:SelA16 Batch
			//		When:9/11/12
			//		EditedBy:Karthik
			//		When:9/11/12
			// Is it checked
			if(driver.findElement(By.xpath(xPath)).getAttribute("checked").equalsIgnoreCase("checked")){
				//Then do not do anything
			} else {
				driver.findElement(By.xpath(xPath)).click();
			}
		}


//		uncheckBox
//		selectRadio
		
		public void navigateBrowser(WebDriver driver, String data){
			//		Purpose: Navigate a browser to a URL
			//		I/P:driver, data
			//		O/P:Nil
			//		CreatedBy:SelA16 Batch
			//		When:9/11/12
			//		EditedBy:Karthik
			//		When:9/11/12
			// Is it checked
			driver.navigate().to(data);
		}
	}

